package com.atguigu.spzx.order.controller;

import com.atguigu.spzx.model.dto.order.OrderInfoDto;
import com.atguigu.spzx.model.pojo.order.OrderInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.TradeVo;
import com.atguigu.spzx.order.service.OrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order/orderInfo")
@Tag(name = "订单接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/auth/trade")
    @Operation(summary = "确认订单")
    public Result<TradeVo> trade() {
        return Result.ok(orderService.trade());
    }

    @PostMapping("/auth/submitOrder")
    @Operation(summary = "提交订单")
    public Result<Long> submitOrder(@RequestBody OrderInfoDto orderInfoDto) {
        return Result.ok(orderService.submitOrder(orderInfoDto));
    }

    @GetMapping("/auth/buy/{skuId}")
    @Operation(summary = "立即购买")
    public Result<TradeVo> buyProduct(@PathVariable("skuId") Long skuId) {
        return Result.ok(orderService.buyProduct(skuId));
    }

    @GetMapping("/auth/{orderId}")
    @Operation(summary = "根据订单Id获取订单信息")
    public Result<OrderInfo> getOrderInfoById(@PathVariable("orderId")Long orderId){
        return Result.ok(orderService.getOrderInfoById(orderId));
    }

    @GetMapping("/auth/{page}/{limit}")
    @Operation(summary = "获取订单分页")
    public Result<PageInfo<OrderInfo>> getOrderPage(@PathVariable("page")Integer pageNum,
                                                    @PathVariable("limit")Integer pageSize,
                                                    Integer orderStatus){
        return Result.ok(orderService.getOrderPage(pageNum,pageSize,orderStatus));
    }

    @GetMapping("/auth/findOrderInfoByOrderNo/{orderNo}")
    @Operation(summary = "根据订单号获取订单")
    public Result<OrderInfo> findByOrderNo(@PathVariable("orderNo")String orderNo){
        return Result.ok(orderService.findByOrderNo(orderNo));
    }
}
